﻿Imports System.Data.SqlClient
Public Class clsE_Despachos
    Private mintIdDespacho As Integer
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdOperador As Integer
    Private mstrNombreOperador As String
    Private mdatFecha As Date
    Private mintDia As Integer
    Private mintMes As Integer
    Private mintAnio As Integer
    Private mstrRol As String
    Private mdatSalidaProg As String
    Private mdatSalidaReal As String
    Private mintRealizado As Integer
    Private mintJustificado As Integer
    Private mstrJustificacion As String
    Private mdblMinutos As Double
    Public Property IdDespacho() As Integer
        Get
            Return mintIdDespacho
        End Get
        Set(ByVal value As Integer)
            mintIdDespacho = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property

    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Dia() As Integer
        Get
            Return mintDia
        End Get
        Set(ByVal value As Integer)
            mintDia = value
        End Set
    End Property
    Public Property Mes() As Integer
        Get
            Return mintMes
        End Get
        Set(ByVal value As Integer)
            mintMes = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property Rol() As String
        Get
            Return mstrRol
        End Get
        Set(ByVal value As String)
            mstrRol = value
        End Set
    End Property
    Public Property SalidaProg() As String
        Get
            Return mdatSalidaProg
        End Get
        Set(ByVal value As String)
            mdatSalidaProg = value
        End Set
    End Property
    Public Property SalidaReal() As String
        Get
            Return mdatSalidaReal
        End Get
        Set(ByVal value As String)
            mdatSalidaReal = value
        End Set
    End Property
    Public Property Realizado() As Integer
        Get
            Return mintRealizado
        End Get
        Set(ByVal value As Integer)
            mintRealizado = value
        End Set
    End Property
    Public Property Justificado() As Integer
        Get
            Return mintJustificado
        End Get
        Set(ByVal value As Integer)
            mintJustificado = value
        End Set
    End Property
    Public Property Justificacion() As String
        Get
            Return mstrJustificacion
        End Get
        Set(ByVal value As String)
            mstrJustificacion = value
        End Set
    End Property
    Public Property Minutos() As Double
        Get
            Return mdblMinutos
        End Get
        Set(ByVal value As Double)
            mdblMinutos = value

        End Set
    End Property
    Public Sub New()
        mintIdDespacho = 0
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdOperador = 0
        mstrNombreOperador = ""
        mdatFecha = Now()
        mintDia = 0
        mintMes = 0
        mintAnio = 0
        mstrRol = ""
        mdatSalidaProg = ""
        mdatSalidaReal = ""
        mintRealizado = 0
        mintJustificado = 0
        mstrJustificacion = ""
        mdblMinutos = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Despachos (" & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdOperador," & _
                            "NombreOperador," & _
                            "Fecha," & _
                            "Dia," & _
                            "Mes," & _
                            "Anio," & _
                            "Rol," & _
                            "SalidaProg," & _
                            "SalidaReal," & _
                            "Realizado," & _
                            "Justificado," & _
                            "Justificacion," & _
                            "Minutos) " & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,100)," & _
                            "@IdOperador," & _
                            "substring(@NombreOperador,1,150)," & _
                            "@Fecha," & _
                            "@Dia," & _
                            "@Mes," & _
                            "@Anio," & _
                            "substring(@Rol,1,150)," & _
                            "@SalidaProg," & _
                            "@SalidaReal," & _
                            "@Realizado," & _
                            "@Justificado," & _
                            "substring(@Justificacion,1,300)," & _
                            "@Minutos) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Rol", mstrRol)
        Command.Parameters.AddWithValue("SalidaProg", mdatSalidaProg)
        Command.Parameters.AddWithValue("SalidaReal", mdatSalidaReal)
        Command.Parameters.AddWithValue("Realizado", mintRealizado)
        Command.Parameters.AddWithValue("Justificado", mintJustificado)
        Command.Parameters.AddWithValue("Justificacion", mstrJustificacion)
        Command.Parameters.AddWithValue("Minutos", mdblMinutos)
       
        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de despachos", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update E_Despachos Set " & _
                            "IdAutobus=@IdAutobus," & _
                            "NoEconomico=substring(@NoEconomico,1,50)," & _
                            "IdOperador=@IdOperador," & _
                            "NombreOperador=substring(@NombreOperador,1,50)," & _
                            "Fecha=@Fecha," & _
                            "Dia=@Dia," & _
                            "Mes=@Mes," & _
                            "Anio=@Anio," & _
                            "Rol=substring(@Rol,1,15)," & _
                            "SalidaProg=@SalidaProg," & _
                            "SalidaReal=@SalidaReal," & _
                            "Realizado=@Realizado," & _
                            "Justificado=@Justificado," & _
                            "Justificacion=substring(@Justificacion,1,15)," & _
                            "Minutos=@Minutos " & _
                            " Where IdDespacho=@IdDespacho"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdDespacho", mintIdDespacho)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Rol", mstrRol)
        Command.Parameters.AddWithValue("SalidaProg", mdatSalidaProg)
        Command.Parameters.AddWithValue("SalidaReal", mdatSalidaReal)
        Command.Parameters.AddWithValue("Realizado", mintRealizado)
        Command.Parameters.AddWithValue("Justificado", mintJustificado)
        Command.Parameters.AddWithValue("Justificacion", mstrJustificacion)
        Command.Parameters.AddWithValue("Minutos", mdblMinutos)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de Despachos", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
   
End Class
